using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
// 改为按照场景划分功能 初始场景->登录菜单、选择房间 关卡场景->游玩、退出
public class TransitionManager : Singleton<TransitionManager>
{
    public void LoadLevelScene(string sceneName, int i)
    {
        StartCoroutine(LoadScene(sceneName, i));
    }
    IEnumerator LoadScene(string sceneName, int i)
    {
        // 如果当前场景是 level1 之类的关卡场景，先卸载掉
        if (SceneManager.GetActiveScene().name != "Game")
        {
            SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene());
        }
        // 加载场景
        yield return SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
        // 激活场景
        SceneManager.SetActiveScene(SceneManager.GetSceneByName(sceneName));
        // 呼叫场景加载完毕的事件
        EventManager.CallAfterSceneLoaded(i);
    }
    public void UnLoadLevelScene()
    {
        StartCoroutine(UnLoadScene());
    }
    IEnumerator UnLoadScene()
    {
        if (SceneManager.GetActiveScene().name != "Game")
        {
            yield return SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene());
        }
        yield return null;
    }
}
